<template>
  <div class="markdown-content" v-html="parsedContent"></div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
// @ts-ignore
import { marked } from 'marked';

// 添加具名导出
defineOptions({
  name: 'MarkdownContent'
});

const props = defineProps({
  content: {
    type: String,
    default: ''
  }
});

// 解析Markdown内容为HTML
const parsedContent = computed(() => {
  if (!props.content) return '';
  try {
    return marked(props.content, { 
      breaks: true,
      gfm: true 
    });
  } catch (error) {
    console.error('Error parsing markdown:', error);
    return '<p>Error parsing content.</p>';
  }
});
</script>

<style lang="scss" scoped>
.markdown-content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  // padding: 20px;
  font-family: Arial, sans-serif;
  line-height: 1.6;
  
  :deep(h1) {
    font-size: 28px;
    margin-top: 30px;
    margin-bottom: 20px;
    font-weight: 600;
    color: #232323;
  }

  :deep(h2) {
    font-size: 24px;
    margin-top: 25px;
    margin-bottom: 15px;
    font-weight: 600;
    color: #232323;
  }

  :deep(h3) {
    font-size: 20px;
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
    color: #232323;
  }

  :deep(h4) {
    font-size: 18px;
    margin-top: 16px;
    margin-bottom: 10px;
    font-weight: 600;
    color: #232323;
  }

  :deep(p) {
    margin-bottom: 16px;
    color: #333;
  }

  :deep(ul), :deep(ol) {
    margin-bottom: 16px;
    padding-left: 20px;
    
    li {
      margin-bottom: 8px;
    }
  }

  :deep(blockquote) {
    border-left: 4px solid #ddd;
    padding-left: 16px;
    margin-left: 0;
    margin-right: 0;
    color: #666;
  }

  :deep(code) {
    font-family: monospace;
    background-color: #f5f5f5;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
  }

  :deep(pre) {
    background-color: #f5f5f5;
    padding: 16px;
    border-radius: 4px;
    overflow-x: auto;
    margin-bottom: 16px;
    
    code {
      background-color: transparent;
      padding: 0;
    }
  }

  :deep(a) {
    color: #007bff;
    text-decoration: none;
    
    &:hover {
      text-decoration: underline;
    }
  }

  :deep(table) {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    
    th, td {
      border: 1px solid #ddd;
      padding: 8px;
    }
    
    th {
      background-color: #f5f5f5;
      font-weight: 600;
    }
    
    tr:nth-child(even) {
      background-color: #f9f9f9;
    }
  }

  :deep(hr) {
    border: 0;
    border-top: 1px solid #eee;
    margin: 20px 0;
  }

  :deep(img) {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 16px 0;
  }
}

/* 移动端适配 */
@media (max-width: 768px) {
  .markdown-content {
    padding: 15px;
    
    :deep(h1) {
      font-size: 24px;
    }
    
    :deep(h2) {
      font-size: 22px;
    }
    
    :deep(h3) {
      font-size: 18px;
    }
    
    :deep(h4) {
      font-size: 16px;
    }
  }
}
</style> 